Ext.onReady(function() {

      var Tree = Ext.tree;// set the root node
      var root = new Tree.AsyncTreeNode({
            text      : '客户管理系统',
            draggable : false,
            id        : '-1'
          });
      var treePanel = new Tree.TreePanel({
            useArrows       : true,
            autoScroll      : true,
            animate         : true,
            enableDD        : false,
            containerScroll : true,
            root            : root,
            loader          : new Tree.TreeLoader({
                  dataUrl : 'permission.json'
                })
          });

      treePanel.on('checkchange', function(node, checked) {
            if (checked) {
              node.getUI().addClass('complete');
            } else {
              node.getUI().removeClass('complete');
            }

            node.expand();
            node.attributes.checked = checked;

            node.eachChild(function(child) {
                  child.ui.toggleCheck(checked);
                  child.attributes.checked = checked;
                });

          }, treePanel);

      treePanel.expandAll();

      var navPanel = new Ext.Panel({
            renderTo    : Ext.getBody(),
            width       : 350,
            collapsible : true,
            defaults    : {
              border    : false,
              bodyStyle : 'padding:5px'
            },
            tbar        : ['->', {
                  text    : 'Add',
                  handler : function() {
                    addNode();
                  }
                }, {
                  text    : 'Debug',
                  handler : function() {
                    var selNodes = treePanel.getChecked();
                    Ext.each(selNodes, function(node) {
                          console
                              .debug(node.parentNode.text + '  ' + node.text)
                        });
                  }
                }],
            items       : [treePanel]
          });

      function addNode() {
        var newNode = new Ext.tree.TreeNode({
              checked : true,
              text    : '节点名称'
            });
        root.insertBefore(newNode, null);// 插入新节点
        root.expand(true);// 展开

        var nodeRead = new Ext.tree.TreeNode({
              checked : true,
              cls     : 'complete',
              text    : '只读'
            });
        var nodeModify = new Ext.tree.TreeNode({
              checked : true,
              cls     : 'complete',
              text    : '修改'
            });
        var nodeRemove = new Ext.tree.TreeNode({
              checked : true,
              cls     : 'complete',
              text    : '删除'
            });
        var nodeExport = new Ext.tree.TreeNode({
              checked : true,
              cls     : 'complete',
              text    : '导出'
            });

        newNode.insertBefore(nodeRead, null);
        newNode.insertBefore(nodeModify, null);
        newNode.insertBefore(nodeRemove, null);
        newNode.insertBefore(nodeExport, null);
      }

    });